import numpy as np
def Dtw(a, b):
    dis = np.full((len(a) + 1, len(b) + 1), np.inf)
    dis[0, 0] = 0
    for i in range(0, len(a)):
        for j in range(0, len(b)):
            dis[i + 1, j + 1] = (a[i] - b[j]) ** 2
    for i in range(1, len(a) + 1):
        for j in range(1, len(b) + 1):
            dis[i, j] = min(dis[i - 1, j - 1], dis[i, j - 1], dis[i - 1, j]) + dis[i, j]
    result = dis[len(a)-1, len(b)-1] / (len(a) + len(b))
    return result


x = [2, 0, 1, 1, 2, 4, 2, 1, 2, 0]
y = [1, 1, 2, 4, 2, 1, 2, 0]
print(Dtw(x, y))